<template>
	<view class="AddPerson">
		<view class="warps">
			<u-form :model="form" ref="uForm">
				<u-form-item :labelWidth="120" label="账套名">
					<u-input v-model="form.name" />
				</u-form-item>
				<u-form-item :labelWidth="120" label="绑定类型">
					<!-- <u-input v-model="form.intro" /> -->
					<u-radio-group v-model="form.radio" @change="radioGroupChange">
						<u-radio @change="radioChange" v-for="(item, index) in list" :key="index" :name="item.name" :disabled="item.disabled">
							{{item.name}}
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item :labelWidth="120" :label="form.radio">
					<u-input v-model="form.card" type="number" />
				</u-form-item>
				<u-form-item :labelWidth="120" label="密码">
					<u-input v-model="form.pwd" type="password" />
				</u-form-item>

			</u-form>
			<view style="text-align: center;margin-top: 30upx;">
				<u-button size="medium" type="success" @click="AddPerson">绑定</u-button>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import http from '../../common/vmeitime-http/index.js';
	import {
		Base64Encrypt,
		Base64Decrypt,
		Decrypt,
		EncryptAES,
		SHA256,
		RSA_encrypt,
		RSA
	} from '../../utils/crypto_RSA_AES.js'
	export default {
		data() {
			return {
				list: [{
						name: '卡号',
						disabled: false
					},
					{
						name: '手机',
						disabled: false
					},
					{
						name: '身份证',
						disabled: false
					}
				],
				form: {
					name: '',
					radio: '卡号',
					card: '',
					pwd: ''

				}
			}
		},
		methods: {

			AddPerson() {
				if (this.form.name === '') {
					uni.showToast({
						title: '请输入访客姓名！',
						icon: 'none'
					})
					return
				}
				if (this.form.card === '') {
					uni.showToast({
						title: `请输入！${this.form.radio}`,
						icon: 'none'
					})
					return
				}
				if (this.form.pwd === '') {
					uni.showToast({
						title: '请输入密码！',
						icon: 'none'
					})
					return
				}
				const params = [
					this.form.name,
					this.form.card,
					this.form.pwd
				];
				let Loginciphertext = RSA_encrypt().encrypt(params.join(','));
				let idtype = {
					'卡号': '3',
					'手机': '2',
					'身份证': '1'
				}
				let parma = {
					Loginciphertext: Loginciphertext,
					IDType: idtype[this.form.radio]
				}
				http.AddCustomer(parma).then(ress => {
					console.log(ress);
					let res = ress.data;
					if (res.result == 1) {
						uni.setStorageSync('AKey',ress.data.AKey);
						uni.setStorageSync('AIV',ress.data.AIV);
						this.$refs.uToast.show({title:`添加成功`});
						uni.navigateBack();
					}
					if (res.result == -2) {
						this.$refs.uToast.show({title:`账套不存在`});
					}
					if (res.result == -3) {
						this.$refs.uToast.show({title:`人员不存在`});
					}
					if (res.result == -4) {
						this.$refs.uToast.show({title:`人员密码错误`});
					}
					if (res.result == 2) {
						this.$refs.uToast.show({title:`此账套已存在,请添加其他账套`});
					}
					if (res.result == -5) {
						if (this.data.radio == 1) {
							this.$refs.uToast.show({title:`绑定的卡号被多人使用`});
						}
						if (this.data.radio == 2) {
							this.$refs.uToast.show({title:`绑定的手机号被多人使用`});
						}
						if (this.data.radio == 3) {
							this.$refs.uToast.show({title:`绑定的身份证号被多人使用`});
						}

					}
					
				})
			}
		}
	}
</script>

<style lang="scss">
	.AddPerson {
		width: 100%;
		height: 100%;

		.warps {
			width: 700upx;
			height: 100%;
			margin-left: 25upx;
		}
	}
</style>
